﻿Imports System
Imports System.Runtime.InteropServices

Namespace System.Workflow.Runtime.DebugEngine
    Friend Class NativeMethods
        ' Methods
        <DllImport("kernel32.dll", SetLastError:=True)> _
        Public Shared Function CloseHandle(ByVal hObject As IntPtr) As <MarshalAs(UnmanagedType.Bool)> Boolean
        End Function

        <DllImport("kernel32.dll")> _
        Public Shared Function GetCurrentProcess() As IntPtr
        End Function

        <DllImport("kernel32.dll")> _
        Public Shared Function GetCurrentThreadId() As Integer
        End Function

        <DllImport("advapi32.dll", SetLastError:=True)> _
        Public Shared Function GetKernelObjectSecurity(ByVal Handle As IntPtr, ByVal RequestedInformation As SECURITY_INFORMATION, ByVal pSecurityDescriptor As IntPtr, ByVal nLength As UInt32, <Out> ByRef lpnLengthNeeded As UInt32) As Boolean
        End Function

        <DllImport("advapi32.dll", SetLastError:=True)> _
        Public Shared Function OpenProcessToken(ByVal ProcessHandle As IntPtr, ByVal DesiredAccess As UInt32, <Out> ByRef TokenHandle As IntPtr) As Boolean
        End Function

        <DllImport("advapi32.dll", SetLastError:=True)> _
        Public Shared Function RevertToSelf() As Boolean
        End Function

        <DllImport("advapi32.dll", SetLastError:=True)> _
        Public Shared Function SetKernelObjectSecurity(ByVal Handle As IntPtr, ByVal SecurityInformation As SECURITY_INFORMATION, ByVal SecurityDescriptor As IntPtr) As Boolean
        End Function


        ' Fields
        Public Const STANDARD_RIGHTS_REQUIRED As Integer = &HF0000
        Public Const TOKEN_ADJUST_DEFAULT As Integer = &H80
        Public Const TOKEN_ADJUST_GROUPS As Integer = &H40
        Public Const TOKEN_ADJUST_PRIVILEGES As Integer = &H20
        Public Const TOKEN_ADJUST_SESSIONID As Integer = &H100
        Public Const TOKEN_ALL_ACCESS As Integer = &HF00FF
        Public Const TOKEN_ASSIGN_PRIMARY As Integer = 1
        Public Const TOKEN_DUPLICATE As Integer = 2
        Public Const TOKEN_IMPERSONATE As Integer = 4
        Public Const TOKEN_QUERY As Integer = 8
        Public Const TOKEN_QUERY_SOURCE As Integer = &H10

        ' Nested Types
        Public Enum EoAuthnCap
            ' Fields
            AccessControl = 4
            AnyAuthority = &H80
            AppID = 8
            AutoImpersonate = &H400
            [Default] = &H800
            DisableAAA = &H1000
            Dynamic = &H10
            DynamicCloaking = &H40
            MakeFullSIC = &H100
            MutualAuth = 1
            NoCustomMarshal = &H2000
            None = 0
            RequireFullSIC = &H200
            SecureRefs = 2
            StaticCloaking = &H20
        End Enum

        <Flags> _
        Public Enum RpcAuthnLevel
            ' Fields
            [Call] = 3
            Connect = 2
            [Default] = 0
            None = 1
            Pkt = 4
            PktIntegrity = 5
            PktPrivacy = 6
        End Enum

        Public Enum RpcImpLevel
            ' Fields
            Anonymous = 1
            [Default] = 0
            [Delegate] = 4
            Identify = 2
            Impersonate = 3
        End Enum

        <Flags> _
        Public Enum SECURITY_INFORMATION As UInt32
            ' Fields
            DACL_SECURITY_INFORMATION = 4
            GROUP_SECURITY_INFORMATION = 2
            OWNER_SECURITY_INFORMATION = 1
            PROTECTED_DACL_SECURITY_INFORMATION = &H80000000
            PROTECTED_SACL_SECURITY_INFORMATION = &H40000000
            SACL_SECURITY_INFORMATION = 8
            UNPROTECTED_DACL_SECURITY_INFORMATION = &H20000000
            UNPROTECTED_SACL_SECURITY_INFORMATION = &H10000000
        End Enum
    End Class
End Namespace

